# -*- coding: UTF-8 -*-

import datetime
import sys
import time
from sqlalchemy import and_,  func, or_
from typing import Dict, List, Any, Generator

from sqlalchemy import Boolean, Column, DateTime, Integer, String, Index, Table, ForeignKey, text, JSON, TEXT, distinct, FLOAT
from sqlalchemy.orm import Session, relationship
from common.database import Base
from common.database import SessionMixin
from common.utils import is_empty
from core.logger import logger


__all__ = ['AuditInspection']

class AuditInspection(Base, SessionMixin):
    '''
    巡检事件
    '''
    __tablename__ = "audit_inspection"
    user_name = Column(String(32),index=True, nullable=False, comment='巡检人')
    inspection_name = Column(String(32),index=True, nullable=False, comment='巡检名称')
    inspection_type = Column(String(24), nullable=False, comment='巡检类型')
    # success(成功) or failed(失败)
    inspection_result = Column(String(16), nullable=False, comment='巡检结果')
    is_notice = Column(Boolean, default=text('true'), comment="是否通知")
    create_time = Column(DateTime, default=datetime.datetime.now, comment="创建时间")
    comment = Column(String(1024), nullable=True, comment='巡检说明')

    __table_args__ = (
        {
            'mysql_engine': 'innodb',
            'mysql_charset': 'utf8mb4',
            'mysql_collate': 'utf8mb4_unicode_ci',
            'extend_existing': True,
            'mysql_row_format': 'dynamic'
        }
    )

    def __repr__(self):
        return f"<name={self.user_name}, inspect_name:{self.inspect_name}'>"

    def object_to_dict(self, db: Session):
        result = {
            key: getattr(self, key)
            for key in self.__mapper__.c.keys()
        }
        return result

